from pathlib import Path

target_directory = Path(r"F:")
for folder in target_directory.glob('**/*'):
    try:
        # 检查是否为目录且为空
        if folder.is_dir() and not any(folder.iterdir()):
            print(folder)
            try:
                folder.rmdir()
            except OSError:
                print(f"{folder} 删除失败")
    except PermissionError:
        print(f"{folder} 访问被拒绝")
        continue  # 如果访问被拒绝（如系统保护目录），则简单地忽略此目录
